package org.jeecg.modules.ParameterModule.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.ParameterModule.entity.*;
import org.jeecg.modules.ParameterModule.service.CategoryInfoService;
import org.jeecg.modules.gwcjava.jiekou.entity.MlccUserInfo;
import org.jeecg.modules.gwcjava.jiekou.entity.StoreInfo;
import org.jeecg.modules.gwcjava.jiekou.service.BusinessLogicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 后台类别配置
 * */
@Api(tags="后台类别配置")
@RestController
@RequestMapping("/admin/parameter")
@Slf4j
public class CategoryInfoController {
    @Autowired
    private CategoryInfoService parameterService;

    /**
     * 总后台查询+类别列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/categoryinfoList")
    public Result<?> queryPageList_category(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                         @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                         String queryName,String queryCode) {
//        QueryWrapper<MlccCategoryInfo> queryWrapper = QueryGenerator.initQueryWrapper(categoryInfo, req.getParameterMap());
        Page<MlccCategoryInfo> page = new Page<MlccCategoryInfo>(pageNo, pageSize);
        IPage<MlccCategoryInfo> pageList = parameterService.query_CategoryPageList(page,queryName,queryCode);
        return Result.ok(pageList);
    }

    /**
     * 总后台查询+测试类别列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/test_categoryinfoList")
    public Result<?> query_test_categoryinfoList(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                            @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                            String queryName,String queryCode) {
        Page<MlccCategoryTestInfo> page = new Page<MlccCategoryTestInfo>(pageNo, pageSize);
        IPage<MlccCategoryTestInfo> pageList = parameterService.query_testCategoryPageList(page,queryName,queryCode);
        return Result.ok(pageList);
    }

    /**
     * 根据id查询类别品类详情
     * @return
     */
    @GetMapping(value = "/query_testcategoryDetail")
    public Result<?> query_testcategoryDetail(@RequestParam(name="id")String category_id){
        MlccCategoryTestInfo datainfo = parameterService.select_testcategoryDetail(category_id);
        if(datainfo!=null){
            return Result.ok(datainfo);
        }else{
            return Result.error("未找到对应数据");
        }
    }

    /**
     * 添加品类
     * @param
     * @return boolean
     */
    @PostMapping(value = "/add_category_pinglei")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> add_category_pinglei(@RequestBody MlccCategoryTestInfo testInfo) {
        System.out.println(testInfo.getCategoryName() + "===" + testInfo.getImg());
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sysuser_id = sysUser.getId();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getCategoryName()==null || "".equals(testInfo.getCategoryName())){
                return Result.error("品类名称不能为空");
            }
            if(testInfo.getSex()==null || "".equals(testInfo.getSex())){
                return Result.error("品类性别不能为空");
            }
            if(testInfo.getNumbers()==null || "".equals(testInfo.getNumbers())){
                return Result.error("序号不能为空");
            }
            if(testInfo.getImg()==null || "".equals(testInfo.getImg())){
                return Result.error("图片不能为空");
            }
            Long startTs = System.currentTimeMillis(); // 当前时间戳
            //8位随机数
            int random=new Random().nextInt(1000000)+1;//为变量赋随机值1-99999999;
            String category_code = "PL"+startTs.toString()+random;
            //赋值品类编号
            testInfo.setCategoryCode(category_code);
            //赋值品类性别
            if("54".equals(testInfo.getSex())){
                testInfo.setCategorySex(1);
            }else if("55".equals(testInfo.getSex())){
                testInfo.setCategorySex(2);
            }else{
                testInfo.setCategorySex(0);
            }
            //赋值模块id
            testInfo.setParentId("2");
            testInfo.setIsType(2);
            //赋值上级ids
            testInfo.setTopid(testInfo.getSex());
            //赋值创建人信息
            testInfo.setCreateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            int code = parameterService.add_category_pinglei(testInfo);
            if(code>0){
                //根据品类编号查询详情
                MlccCategoryTestInfo pingleidetail = parameterService.select_testcategoryDetailBycode(category_code);
                if(pingleidetail!=null){
                    //根据品类编号修改品类编号
                    parameterService.update_gongyicode_code("PL-00"+pingleidetail.getId(),category_code);
                }
                return Result.ok("添加成功");
            }else {
                return Result.error("添加失败");
            }
        }catch (Exception e){
            return Result.error("添加失败，参数错误");
        }
    }

    /**
     * 修改测试品类
     * @param
     * @return boolean
     */
    @PutMapping(value = "/update_category_pinglei")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> update_category_pinglei(@RequestBody MlccCategoryTestInfo testInfo) {
        System.out.println(testInfo.getCategoryName() + "===" + testInfo.getImg());
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getCategoryName()==null || "".equals(testInfo.getCategoryName())){
                return Result.error("品类名称不能为空");
            }
            if(testInfo.getSex()==null || "".equals(testInfo.getSex())){
                return Result.error("品类性别不能为空");
            }
            if(testInfo.getNumbers()==null || "".equals(testInfo.getNumbers())){
                return Result.error("序号不能为空");
            }
            if(testInfo.getImg()==null || "".equals(testInfo.getImg())){
                return Result.error("图片不能为空");
            }
            testInfo.setUpdateBy(create_by);
            //赋值品类性别
            if("54".equals(testInfo.getSex())){
                testInfo.setCategorySex(1);
            }else if("55".equals(testInfo.getSex())){
                testInfo.setCategorySex(2);
            }else{
                testInfo.setCategorySex(0);
            }
            //赋值上级ids
            testInfo.setTopid(testInfo.getSex());
            int code = parameterService.update_category_pingleiName(testInfo);
            if(code>0){
                return Result.ok("编辑成功");
            }else {
                return Result.error("编辑失败");
            }
        }catch (Exception e){
            return Result.error("编辑失败，参数错误");
        }
    }

    /**
     * 根据品类id统计数据
     * @return
     */
    @GetMapping(value = "/count_data_pingleiId")
    public Result<?> count_data_pingleiId(@RequestParam(name="category_id")String category_id){
        CountDataInfo countDataInfo = new CountDataInfo();
        int xiuzinum1 = parameterService.count_xiuzi_color(category_id);
        int xiuzinum2 = parameterService.count_xiuzi_font(category_id);
        int xiuzinum3 = parameterService.count_xiuzi_img(category_id);
        int xiuzinum4 = parameterService.count_xiuzi(category_id);
        countDataInfo.setDingzhiNum(parameterService.count_dingzhi(category_id));
        countDataInfo.setHuchiNum(parameterService.count_huchi(category_id));
        countDataInfo.setXiuziNum(xiuzinum1+xiuzinum2+xiuzinum3+xiuzinum4);
        countDataInfo.setZhuangseNum(parameterService.count_zhuangse(category_id));
        countDataInfo.setJingtiNum(parameterService.count_jing_bodysize(category_id));
        countDataInfo.setChengNum(parameterService.count_cheng_bodysize(category_id));
        countDataInfo.setFanxiuNum(parameterService.count_fanxiu(category_id));
        countDataInfo.setGongyiNum(parameterService.count_gongyi(category_id));
        return Result.ok(countDataInfo);
    }

    /**
     * 根据品类id查询定制项
     * @return
     */
    @GetMapping(value = "/query_dingzhiBypingleiId")
    public Result<?> query_dingzhiBypingleiId(@RequestParam(name="category_id")String category_id){
        List<SmalltemplateTestInfo> datalist = parameterService.query_dingzhiBycategoryId(category_id);
        if(datalist.size()>0){
            return Result.ok(datalist);
        }else{
            return Result.error("未找到对应数据");
        }
    }

    /**
     * 根据定制id查询定制项
     * @return
     */
    @GetMapping(value = "/query_dingzhiBydingzhiId")
    public Result<?> query_dingzhiBydingzhiId(@RequestParam(name="dinghzi_id")String dinghzi_id){
        SmalltemplateTestInfo datainfo = parameterService.query_dingzhiBydingzhId(dinghzi_id);
        if(datainfo!=null){
            return Result.ok(datainfo);
        }else{
            return Result.error("未找到对应数据");
        }
    }

    /**
     * 添加定制项
     * @param
     * @return boolean
     */
    @PostMapping(value = "/add_dingzhi")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> add_dingzhi(@RequestBody SmalltemplateTestInfo testInfo) {
        System.out.println(testInfo.getParameter() + "===" + testInfo.getNumbers());
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getParameter()==null || "".equals(testInfo.getParameter())){
                return Result.error("定制项名称不能为空");
            }
            Long startTs = System.currentTimeMillis(); // 当前时间戳
            //8位随机数
            int random=new Random().nextInt(100)+1;//为变量赋随机值1-99999999;
            String category_code = "DZX-"+startTs.toString()+random;
            //赋值编号
            testInfo.setCode(category_code);
            //赋值模块id
            testInfo.setModuleId("3");
            testInfo.setIstype(0);
            //赋值创建人信息
            testInfo.setCreateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            int code = parameterService.add_dingzhi(testInfo);
            if(code>0){
                return Result.ok("添加成功");
            }else {
                return Result.error("添加失败");
            }
        }catch (Exception e){
            return Result.error("添加失败，参数错误");
        }
    }

    /**
     * 修改定制项
     * @param
     * @return boolean
     */
    @PutMapping(value = "/update_dingzhi")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> update_dingzhi(@RequestBody SmalltemplateTestInfo testInfo) {
        System.out.println(testInfo.getParameter() + "===" + testInfo.getNumbers());
        if(testInfo.getId()==null || "".equals(testInfo.getId())){
            return Result.error("定制id不能为空");
        }
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getParameter()==null || "".equals(testInfo.getParameter())){
                return Result.error("定制项名称不能为空");
            }
            //赋值修改人信息
            testInfo.setUpdateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            int code = parameterService.update_dingzhi(testInfo);
            if(code>0){
                return Result.ok("修改成功");
            }else {
                return Result.error("修改失败");
            }
        }catch (Exception e){
            return Result.error("修改失败，参数错误");
        }
    }

    /**
     * 删除定制项
     * @param
     * @return boolean
     */
    @PutMapping(value = "/delete_dingzhi")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> delete_dingzhi(@RequestBody Map<String,Object> params) {
        String dingzhi_id = params.get("dingzhi_id").toString();
        System.out.println("===" + dingzhi_id);
        if(dingzhi_id==null || "".equals(dingzhi_id)){
            return Result.error("定制id不能为空");
        }
        try {
            int code = parameterService.delete_dingzhi(dingzhi_id);
            if(code>0){
                return Result.ok("删除成功");
            }else {
                return Result.error("删除失败");
            }
        }catch (Exception e){
            return Result.error("删除失败，参数错误");
        }
    }

    /**
     * 总后台查询+测试定制项下的参数列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/test_dignzhipartmer")
    public Result<?> query_test_dignzhipartmer(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                                 @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                                 String topcategory_id,String module_id,String queryName) {
        Page<MlccCategoryTestInfo> page = new Page<MlccCategoryTestInfo>(pageNo, pageSize);
        IPage<MlccCategoryTestInfo> pageList = parameterService.query_testCanshuPageList(page,topcategory_id,module_id,queryName);
        return Result.ok(pageList);
    }

    /**
     * 总后台查询+测试定制项下的所有参数列表
     * @return
     */
    @GetMapping(value = "/test_all_dignzhipartmer")
    public Result<?> query_test_all_dignzhipartmer(String module_id) {
        List<MlccCategoryTestInfo> pageList = parameterService.querycanshuall(module_id);
        return Result.ok(pageList);
    }

    /**
     * 添加定制项下的参数
     * @param
     * @return boolean
     */
    @PostMapping(value = "/add_dingzhi_canshu")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> add_dingzhi_canshu(@RequestBody MlccCategoryTestInfo testInfo) {
        System.out.println(testInfo.getCategoryName() + "===" + testInfo.getParentId());
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getCategoryName()==null || "".equals(testInfo.getCategoryName())){
                return Result.error("参数名称不能为空");
            }
            if(testInfo.getParentId()==null || "".equals(testInfo.getParentId()) || "请选择定制项".equals(testInfo.getParentId())){
                return Result.error("请选择定制项");
            }
            if(testInfo.getCost()==null || "".equals(testInfo.getCost())){
                testInfo.setCost("0.00");
            }
            if(testInfo.getTeamPrice2()==null || "".equals(testInfo.getTeamPrice2())){
                testInfo.setTeamPrice2("0.00");
            }

            MlccCategoryTestInfo mlccCategoryTestInfo = parameterService.queryDingzhiCanshuBycodeid(testInfo.getTopid(),testInfo.getParentId(),testInfo.getCategoryName(),1);
            if(mlccCategoryTestInfo!=null){
                return Result.error("该参数名称在该定制项下面已存在");
            }
            MlccCategoryTestInfo mlccCategoryTestInfo2 = parameterService.queryDingzhiCanshuBycodeid(testInfo.getTopid(),testInfo.getParentId(),testInfo.getCategoryCode(),0);
            if(mlccCategoryTestInfo2!=null){
                return Result.error("该参数编号在该定制项下面已存在");
            }
//            //复制参数编号
//            Long startTs = System.currentTimeMillis(); // 当前时间戳
//            //8位随机数
//            int random=new Random().nextInt(100)+1;//为变量赋随机值1-99999999;
//            String serial_number = "CS-"+startTs;
//            testInfo.setCategoryCode(serial_number);
            //赋值创建人信息
            testInfo.setCreateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            testInfo.setIsType(0);
            testInfo.setCategorySex(0);
            int code = parameterService.add_dingzhi_canshu(testInfo);
            if(code>0){
                return Result.ok("添加成功");
            }else {
                return Result.error("添加失败");
            }
        }catch (Exception e){
            return Result.error("参数编码有相同，请先删除已有相同的编码");
        }
    }

    /**
     * 修改定制项下的参数
     * @param
     * @return boolean
     */
    @PutMapping(value = "/update_dingzhi_canshu")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> update_dingzhi_canshu(@RequestBody MlccCategoryTestInfo testInfo) {
        System.out.println(testInfo.getCategoryName() + "===" + testInfo.getCategoryCode());
        if(testInfo.getId()==null || "".equals(testInfo.getId())){
            return Result.error("参数id不能为空");
        }
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getCategoryName()==null || "".equals(testInfo.getCategoryName())){
                return Result.error("参数名称不能为空");
            }
            if(testInfo.getCost()==null || "".equals(testInfo.getCost())){
                testInfo.setCost("0.00");
            }
            if(testInfo.getTeamPrice2()==null || "".equals(testInfo.getTeamPrice2())){
                testInfo.setTeamPrice2("0.00");
            }
            //赋值修改人信息
            testInfo.setUpdateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            int code = parameterService.update_dingzhi_canshu(testInfo);
            if(code>0){
                return Result.ok("修改成功");
            }else {
                return Result.error("修改失败");
            }
        }catch (Exception e){
            return Result.error("修改失败，参数错误");
        }
    }

    /**
     * 删除定制项下的参数
     * @param
     * @return boolean
     */
    @PutMapping(value = "/delete_dingzhi_canshu")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> delete_dingzhi_canshu(@RequestBody Map<String,Object> params) {
        String canshu_id = params.get("canshu_id").toString();
        System.out.println("===" + canshu_id);
        if(canshu_id==null || "".equals(canshu_id)){
            return Result.error("定制id不能为空");
        }
        try {
            int code = parameterService.delete_dingzhi_canshu(canshu_id);
            if(code>0){
                return Result.ok("删除成功");
            }else {
                return Result.error("删除失败");
            }
        }catch (Exception e){
            return Result.error("删除失败，参数错误");
        }
    }

    /**
     * 总后台查询+测试品类互斥项
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/test_pingleiHuchi")
    public Result<?> query_test_pingleiHuchi(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                               @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                             String topid,String queryName,String queryTime) {
        Page<MutexTestInfo> page = new Page<MutexTestInfo>(pageNo, pageSize);
        IPage<MutexTestInfo> pageList = parameterService.query_testHuchiPageList(page,topid,queryName,queryTime);
        if(pageList!=null || pageList.getRecords().size()>0){
            for (int i=0;i<pageList.getRecords().size();i++){
                String categoryNames ="";
                if(pageList.getRecords().get(i).getCategoryOther()!=null){
                    String[] idS = pageList.getRecords().get(i).getCategoryOther().split(",");
                    for (String s:idS){
                        MlccCategoryTestInfo datainfo = parameterService.select_testcategoryDetail(s);
                        if(datainfo!=null){
                            categoryNames+=datainfo.getCategoryName()+",";
                        }
                    }
                }
                if(categoryNames==null || "".equals(categoryNames)){
                    pageList.getRecords().get(i).setCategoryOtherName("");
                }else {
                    pageList.getRecords().get(i).setCategoryOtherName(categoryNames.substring(0,categoryNames.length()-1));
                }
            }
        }
        return Result.ok(pageList);
    }

    /**
     * 添加互斥项
     * @param
     * @return boolean
     */
    @PostMapping(value = "/add_huchi")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> add_huchi(@RequestBody MutexTestInfo testInfo) {
        System.out.println(testInfo.getMutexName() + "===" + testInfo.getCode());
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getMutexName()==null || "".equals(testInfo.getMutexName())){
                return Result.error("互斥项名称不能为空");
            }
            if(testInfo.getDingzhi1()==null || "".equals(testInfo.getDingzhi1())){
                return Result.error("定制项不能为空");
            }
            if(testInfo.getCategoryId()==null || "".equals(testInfo.getCategoryId())){
                return Result.error("参数不能为空");
            }
            if(testInfo.getDingzhi2()==null || "".equals(testInfo.getDingzhi2())){
                return Result.error("互斥定制项不能为空");
            }
            if(testInfo.getCategoryOther()==null || "".equals(testInfo.getCategoryOther())){
                return Result.error("互斥参数不能为空");
            }
            Long startTs = System.currentTimeMillis(); // 当前时间戳
            //8位随机数
            int random=new Random().nextInt(100)+1;//为变量赋随机值1-99999999;
            String bianhao_code = "HC-"+startTs.toString()+random;
            testInfo.setCode(bianhao_code);
            //赋值创建人信息
            testInfo.setCreateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            int code = parameterService.add_huchi(testInfo);
            if(code>0){
                return Result.ok("添加成功");
            }else {
                return Result.error("添加失败");
            }
        }catch (Exception e){
            return Result.error("添加失败，参数错误");
        }
    }

    /**
     * 修改互斥项
     * @param
     * @return boolean
     */
    @PutMapping(value = "/update_huchi")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> update_huchi(@RequestBody MutexTestInfo testInfo) {
        if(testInfo.getId()==null || "".equals(testInfo.getId())){
            return Result.error("参数id不能为空");
        }
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getMutexName()==null || "".equals(testInfo.getMutexName())){
                return Result.error("互斥项名称不能为空");
            }
            if(testInfo.getDingzhi1()==null || "".equals(testInfo.getDingzhi1())){
                return Result.error("定制项不能为空");
            }
            if(testInfo.getCategoryId()==null || "".equals(testInfo.getCategoryId())){
                return Result.error("参数不能为空");
            }
            if(testInfo.getDingzhi2()==null || "".equals(testInfo.getDingzhi2())){
                return Result.error("互斥定制项不能为空");
            }
            if(testInfo.getCategoryOther()==null || "".equals(testInfo.getCategoryOther())){
                return Result.error("互斥参数不能为空");
            }
            //定制项
            SmalltemplateTestInfo detail0 = parameterService.select_testDingzhiByname(testInfo.getDingzhi1());
            if(detail0!=null){
                testInfo.setDingzhi1(detail0.getId().toString());
            }
            //品类
            MlccCategoryTestInfo detail1 = parameterService.select_testlbDetailByname(testInfo.getCategoryId());
            if(detail1!=null){
                testInfo.setCategoryId(detail1.getId().toString());
            }
            //定制项2
            SmalltemplateTestInfo detail2 = parameterService.select_testDingzhiByname(testInfo.getDingzhi2());
            if(detail2!=null){
                testInfo.setDingzhi2(detail2.getId().toString());
            }
            String othercanshu="";
            if(testInfo.getCategoryOther()!=null && !"".equals(testInfo.getCategoryOther())){
                String regEx="[\n`~!@#$%^&*+=|{}':;'\\[\\].<>/?~！@#￥%……&*——+|{}【】‘；：”“’。 、？]";
                String aa = "";//这里是将特殊字符换为aa字符串,""代表直接去掉
                Pattern p = Pattern.compile(regEx);
                Matcher m = p.matcher(testInfo.getCategoryOther());//这里把想要替换的字符串传进来
                othercanshu = m.replaceAll(aa).trim();
            }
            System.out.println("获取的部门id===="+othercanshu);
            String bumenend="";
            if(othercanshu!=null && !"".equals(othercanshu)){
                if(othercanshu.contains(",")){
                    String idString = othercanshu;
                    String[] idS=idString.split(",");
                    othercanshu="";
                    for(String s:idS){
                        boolean zheng=isNumeric(s);
                        System.out.println("没进来吗==="+zheng);
                        if(zheng==false){
                            MlccCategoryTestInfo detail = parameterService.select_testlbDetailByname(s);
                            if(detail!=null){
                                System.out.println("没进来吗22222==="+detail.getId());
                                othercanshu+=(detail.getId()+",");
                            }
                        }else{
                            othercanshu+=s+",";
                        }
                    }
                    bumenend = othercanshu.substring(0,othercanshu.length()-1);
                }else{
                    boolean zheng=isNumeric(othercanshu);
                    System.out.println("金拉埃没==="+zheng);
                    if(zheng==false){
                        MlccCategoryTestInfo detail = parameterService.select_testlbDetailByname(othercanshu);
                        if(detail!=null){
                            othercanshu=detail.getId().toString();
                        }
                    }
                    bumenend=othercanshu;
                    System.out.println("金拉埃没222==="+bumenend);
                }
            }
            //赋值修改人信息
            testInfo.setUpdateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            //赋值参数
            testInfo.setCategoryOther(bumenend);
            int code = parameterService.update_huchi(testInfo);
            if(code>0){
                return Result.ok("修改成功");
            }else {
                return Result.error("修改失败");
            }
        }catch (Exception e){
            return Result.error("修改失败，参数错误");
        }
    }

    //判断是否是整数
    public static boolean isNumeric(String string){
        Pattern pattern = Pattern.compile("[0-9]*");
        return pattern.matcher(string).matches();
    }

    /**
     * 删除互斥项
     * @param
     * @return boolean
     */
    @PutMapping(value = "/delete_huchi")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> delete_huchi(@RequestBody Map<String,Object> params) {
        String huchi_id = params.get("huchi_id").toString();
        System.out.println("===" + huchi_id);
        if(huchi_id==null || "".equals(huchi_id)){
            return Result.error("id不能为空");
        }
        try {
            int code = parameterService.delete_huchi(huchi_id);
            if(code>0){
                return Result.ok("删除成功");
            }else {
                return Result.error("删除失败");
            }
        }catch (Exception e){
            return Result.error("删除失败，参数错误");
        }
    }

    /**
     * 根据互斥id查询互斥详情
     * @return
     */
    @GetMapping(value = "/query_huchiByid")
    public Result<?> query_huchiByid(@RequestParam(name="huchi_id")String huchi_id){
        MutexTestInfo datainfo = parameterService.query_huzhiBydId(huchi_id);
        if(datainfo!=null){
            String categoryNames ="";
            String[] idS = datainfo.getCategoryOther().split(",");
            for (String s:idS){
                MlccCategoryTestInfo datainfo2 = parameterService.select_testcategoryDetail(s);
                if(datainfo2!=null){
                    categoryNames+=datainfo2.getCategoryName()+",";
                }
            }
            datainfo.setCategoryOtherName(categoryNames.substring(0,categoryNames.length()-1));
            return Result.ok(datainfo);
        }else{
            return Result.error("未找到对应数据");
        }
    }

    /**
     * 总后台查询+测试部位列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/test_xiuzi_locationlist")
    public Result<?> test_xiuzi_locationlist(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                                 @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                             String category_id,String queryName,String queryTime) {
        Page<CategoryLocationTestInfo> page = new Page<CategoryLocationTestInfo>(pageNo, pageSize);
        IPage<CategoryLocationTestInfo> pageList = parameterService.query_testlocaltionPageList(page,category_id,queryName,queryTime);
        return Result.ok(pageList);
    }
    /**
     * 总后台查询+测试颜色列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/test_xiuzi_colorlist")
    public Result<?> test_xiuzi_colorlist(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                             @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                          String category_id,String queryName,String queryTime) {
        Page<EmbroideredColorTestInfo> page = new Page<EmbroideredColorTestInfo>(pageNo, pageSize);
        IPage<EmbroideredColorTestInfo> pageList = parameterService.query_testColorPageList(page,category_id,queryName,queryTime);
        return Result.ok(pageList);
    }
    /**
     * 总后台查询+测试部位列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/test_xiuzi_imglist")
    public Result<?> test_xiuzi_imglist(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                             @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                        String category_id,String queryName,String queryTime) {
        Page<EmbroideredFontTestInfo> page = new Page<EmbroideredFontTestInfo>(pageNo, pageSize);
        IPage<EmbroideredFontTestInfo> pageList = parameterService.query_testImgPageList(page,category_id,queryName,queryTime);
        return Result.ok(pageList);
    }
    /**
     * 总后台查询+测试字体列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/test_xiuzi_fontlist")
    public Result<?> test_xiuzi_fontlist(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                             @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                         String category_id,String queryName,String queryTime) {
        Page<EmbroideredFontTestInfo> page = new Page<EmbroideredFontTestInfo>(pageNo, pageSize);
        IPage<EmbroideredFontTestInfo> pageList = parameterService.query_testFontPageList(page,category_id,queryName,queryTime);
        return Result.ok(pageList);
    }

    /**
     * 总后台查询+测试绣字高度列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/test_xiuzi_hegihtlist")
    public Result<?> test_xiuzi_hegihtlist(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                         @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                         String category_id,String queryName,String queryTime) {
        Page<EmbroidedHeightInfo> page = new Page<EmbroidedHeightInfo>(pageNo, pageSize);
        IPage<EmbroidedHeightInfo> pageList = parameterService.query_testHeightPageList(page,category_id,queryName,queryTime);
        return Result.ok(pageList);
    }


    /**
     * 添加绣字-部位
     * @param
     * @return boolean
     */
    @PostMapping(value = "/add_xiuzi_location")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> add_xiuzi_location(@RequestBody CategoryLocationTestInfo testInfo) {
        System.out.println(testInfo.getCategoryId() + "===" + testInfo.getXiuziLocaltion());
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getXiuziLocaltion()==null || "".equals(testInfo.getXiuziLocaltion())){
                return Result.error("部位名称不能为空");
            }
            if(testInfo.getNumbers()==null || "".equals(testInfo.getNumbers())){
                testInfo.setNumbers("0");
            }
            if(testInfo.getCode()==null || "".equals(testInfo.getCode())){
                Long startTs = System.currentTimeMillis(); // 当前时间戳
                //8位随机数
                int random=new Random().nextInt(100)+1;//为变量赋随机值1-99999999;
                String bianhao_code = "ZONE"+startTs.toString()+random;
                testInfo.setCode(bianhao_code);
            }
            CategoryLocationTestInfo locationTestInfo = parameterService.query_xiuzi_locationDetailBycode(testInfo.getCode(),testInfo.getCategoryId());
            if(locationTestInfo!=null){
                return Result.error("该部位编号在该品类下面已存在");
            }
            //赋值创建人信息
            testInfo.setCreateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            int code = parameterService.add_xiuzi_location(testInfo);
            if(code>0){
                return Result.ok("添加成功");
            }else {
                return Result.error("添加失败");
            }
        }catch (Exception e){
            return Result.error("添加失败，参数错误");
        }
    }

    /**
     * 修改绣字-部位
     * @param
     * @return boolean
     */
    @PutMapping(value = "/update_xiuzi_location")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> update_xiuzi_location(@RequestBody CategoryLocationTestInfo testInfo) {
        if(testInfo.getId()==null || "".equals(testInfo.getId())){
            return Result.error("参数id不能为空");
        }
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getXiuziLocaltion()==null || "".equals(testInfo.getXiuziLocaltion())){
                return Result.error("部位名称不能为空");
            }
            if(testInfo.getNumbers()==null || "".equals(testInfo.getNumbers())){
                testInfo.setNumbers("0");
            }
            //赋值修改人信息
            testInfo.setUpdateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            int code = parameterService.update_xiuzi_location(testInfo);
            if(code>0){
                return Result.ok("修改成功");
            }else {
                return Result.error("修改失败");
            }
        }catch (Exception e){
            return Result.error("修改失败，参数错误");
        }
    }

    /**
     * 删除绣字-部位
     * @param
     * @return boolean
     */
    @PutMapping(value = "/delete_xiuzi_location")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> delete_xiuzi_location(@RequestBody Map<String,Object> params) {
        String canshu_id = params.get("canshu_id").toString();
        System.out.println("===" + canshu_id);
        if(canshu_id==null || "".equals(canshu_id)){
            return Result.error("定制id不能为空");
        }
        try {
            int code = parameterService.delete_xiuzi_location(canshu_id);
            if(code>0){
                return Result.ok("删除成功");
            }else {
                return Result.error("删除失败");
            }
        }catch (Exception e){
            return Result.error("删除失败，参数错误");
        }
    }

    /**
     * 启用绣字-部位
     * @param
     * @return boolean
     */
    @PutMapping(value = "/qiyong_xiuzi_location")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> qiyong_xiuzi_location(@RequestBody Map<String,Object> params) {
        String canshu_id = params.get("canshu_id").toString();
        String status = params.get("status").toString();
        System.out.println("===" + canshu_id);
        if(canshu_id==null || "".equals(canshu_id)){
            return Result.error("定制id不能为空");
        }
        try {
            int code = parameterService.qiyong_xiuzi_location(canshu_id,status);
            if(code>0){
                return Result.ok("操作成功");
            }else {
                return Result.error("操作失败");
            }
        }catch (Exception e){
            return Result.error("操作失败，参数错误");
        }
    }
    /**
     * 启用绣字-颜色
     * @param
     * @return boolean
     */
    @PutMapping(value = "/qiyong_xiuzi_color")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> qiyong_xiuzi_color(@RequestBody Map<String,Object> params) {
        String canshu_id = params.get("canshu_id").toString();
        String status = params.get("status").toString();
        System.out.println("===" + canshu_id);
        if(canshu_id==null || "".equals(canshu_id)){
            return Result.error("定制id不能为空");
        }
        try {
            int code = parameterService.qiyong_xiuzi_color(canshu_id,status);
            if(code>0){
                return Result.ok("操作成功");
            }else {
                return Result.error("操作失败");
            }
        }catch (Exception e){
            return Result.error("操作失败，参数错误");
        }
    }
    /**
     * 启用绣字-字体图片
     * @param
     * @return boolean
     */
    @PutMapping(value = "/qiyong_xiuzi_fontimg")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> qiyong_xiuzi_fontimg(@RequestBody Map<String,Object> params) {
        String canshu_id = params.get("canshu_id").toString();
        String status = params.get("status").toString();
        System.out.println("===" + canshu_id);
        if(canshu_id==null || "".equals(canshu_id)){
            return Result.error("定制id不能为空");
        }
        try {
            int code = parameterService.qiyong_xiuzi_fontimg(canshu_id,status);
            if(code>0){
                return Result.ok("操作成功");
            }else {
                return Result.error("操作失败");
            }
        }catch (Exception e){
            return Result.error("操作失败，参数错误");
        }
    }

    /**
     * 添加绣字-颜色
     * @param
     * @return boolean
     */
    @PostMapping(value = "/add_xiuzi_color")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> add_xiuzi_color(@RequestBody EmbroideredColorTestInfo testInfo) {
        System.out.println(testInfo.getCategoryId() + "===");
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getColorName()==null || "".equals(testInfo.getColorName())){
                return Result.error("颜色名称不能为空");
            }
            if(testInfo.getNumbers()==null || "".equals(testInfo.getNumbers())){
                testInfo.setNumbers("0");
            }
//            if(testInfo.getCode()==null || "".equals(testInfo.getCode())){
//                Long startTs = System.currentTimeMillis(); // 当前时间戳
//                //8位随机数
//                int random=new Random().nextInt(100)+1;//为变量赋随机值1-99999999;
//                String bianhao_code = "C-"+startTs.toString()+random;
//                testInfo.setCode(bianhao_code);
//            }
            EmbroideredColorTestInfo colorTestInfo = parameterService.query_xiuzi_colorDetailBycode(testInfo.getCode(),testInfo.getCategoryId());
            if(colorTestInfo!=null){
                return Result.error("该编号在该品类下面已存在");
            }
            //赋值创建人信息
            testInfo.setCreateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            int code = parameterService.add_xiuzi_color(testInfo);
            if(code>0){
                return Result.ok("添加成功");
            }else {
                return Result.error("添加失败");
            }
        }catch (Exception e){
            return Result.error("添加失败，参数错误");
        }
    }

    /**
     * 修改绣字-颜色
     * @param
     * @return boolean
     */
    @PutMapping(value = "/update_xiuzi_color")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> update_xiuzi_color(@RequestBody EmbroideredColorTestInfo testInfo) {
        if(testInfo.getId()==null || "".equals(testInfo.getId())){
            return Result.error("参数id不能为空");
        }
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getColorName()==null || "".equals(testInfo.getColorName())){
                return Result.error("部位名称不能为空");
            }
            if(testInfo.getNumbers()==null || "".equals(testInfo.getNumbers())){
                testInfo.setNumbers("0");
            }
            //赋值修改人信息
            testInfo.setUpdateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            int code = parameterService.update_xiuzi_color(testInfo);
            if(code>0){
                return Result.ok("修改成功");
            }else {
                return Result.error("修改失败");
            }
        }catch (Exception e){
            return Result.error("修改失败，参数错误");
        }
    }

    /**
     * 删除绣字-颜色
     * @param
     * @return boolean
     */
    @PutMapping(value = "/delete_xiuzi_color")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> delete_xiuzi_color(@RequestBody Map<String,Object> params) {
        String canshu_id = params.get("canshu_id").toString();
        System.out.println("===" + canshu_id);
        if(canshu_id==null || "".equals(canshu_id)){
            return Result.error("定制id不能为空");
        }
        try {
            int code = parameterService.delete_xiuzi_color(canshu_id);
            if(code>0){
                return Result.ok("删除成功");
            }else {
                return Result.error("删除失败");
            }
        }catch (Exception e){
            return Result.error("删除失败，参数错误");
        }
    }

    /**
     * 添加绣字-字体或图片
     * @param
     * @return boolean
     */
    @PostMapping(value = "/add_xiuzi_fontImg")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> add_xiuzi_fontImg(@RequestBody EmbroideredFontTestInfo testInfo) {
        System.out.println(testInfo.getCategoryId() + "===");
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getEmbroideredName()==null || "".equals(testInfo.getEmbroideredName())){
                return Result.error("名称不能为空");
            }
            if(testInfo.getNumbers()==null || "".equals(testInfo.getNumbers())){
                testInfo.setNumbers("0");
            }
            Long startTs = System.currentTimeMillis(); // 当前时间戳
            //赋值创建人信息
            testInfo.setCreateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            if("1".equals(testInfo.getIsZitiImg().toString())){
                testInfo.setLeixingName("图片");
//                String bianhao_code = "Y-"+startTs.toString();
//                testInfo.setCode(bianhao_code);
                EmbroideredFontTestInfo fontTestInfo = parameterService.query_xiuzi_fontDetailBycode(testInfo.getCode(),testInfo.getCategoryId(),1);
                if(fontTestInfo!=null){
                    return Result.error("该编号在该品类下面已存在");
                }
                testInfo.setCode(testInfo.getCode());
            }else {
                testInfo.setLeixingName("文字");
//                String bianhao_code = "T-"+startTs.toString();
//                testInfo.setCode(bianhao_code);
                EmbroideredFontTestInfo fontTestInfo = parameterService.query_xiuzi_fontDetailBycode(testInfo.getCode(),testInfo.getCategoryId(),0);
                if(fontTestInfo!=null){
                    return Result.error("该编号在该品类下面已存在");
                }
                testInfo.setCode(testInfo.getCode());
            }
            int code = parameterService.add_xiuzi_fontImg(testInfo);
            if(code>0){
                return Result.ok("添加成功");
            }else {
                return Result.error("添加失败");
            }
        }catch (Exception e){
            return Result.error("添加失败，参数错误");
        }
    }

    /**
     * 修改绣字-字体图片
     * @param
     * @return boolean
     */
    @PutMapping(value = "/update_xiuzi_fontImg")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> update_xiuzi_fontImg(@RequestBody EmbroideredFontTestInfo testInfo) {
        if(testInfo.getId()==null || "".equals(testInfo.getId())){
            return Result.error("参数id不能为空");
        }
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getEmbroideredName()==null || "".equals(testInfo.getEmbroideredName())){
                return Result.error("名称不能为空");
            }
            if(testInfo.getNumbers()==null || "".equals(testInfo.getNumbers())){
                testInfo.setNumbers("0");
            }
            //赋值修改人信息
            testInfo.setUpdateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            if("1".equals(testInfo.getIsZitiImg().toString())){
                testInfo.setLeixingName("图片");
            }else {
                testInfo.setLeixingName("文字");
            }
            int code = parameterService.update_xiuzi_fontImg(testInfo);
            if(code>0){
                return Result.ok("修改成功");
            }else {
                return Result.error("修改失败");
            }
        }catch (Exception e){
            return Result.error("修改失败，参数错误");
        }
    }

    /**
     * 删除绣字-字体图片
     * @param
     * @return boolean
     */
    @PutMapping(value = "/delete_xiuzi_fontImg")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> delete_xiuzi_fontImg(@RequestBody Map<String,Object> params) {
        String canshu_id = params.get("canshu_id").toString();
        System.out.println("===" + canshu_id);
        if(canshu_id==null || "".equals(canshu_id)){
            return Result.error("id不能为空");
        }
        try {
            int code = parameterService.delete_xiuzi_fontImg(canshu_id);
            if(code>0){
                return Result.ok("删除成功");
            }else {
                return Result.error("删除失败");
            }
        }catch (Exception e){
            return Result.error("删除失败，参数错误");
        }
    }

    /**
     * 根据id查询绣字位置详情
     * @return
     */
    @GetMapping(value = "/test_xiuzi_locationDetail")
    public Result<?> test_xiuzi_locationDetail(@RequestParam(name="id")String id){
        CategoryLocationTestInfo datainfo = parameterService.select_test_xiuzi_locationDetail(id);
        if(datainfo!=null){
            return Result.ok(datainfo);
        }else{
            return Result.error("未找到对应数据");
        }
    }
    /**
     * 根据id查询绣字颜色详情
     * @return
     */
    @GetMapping(value = "/test_xiuzi_colorDetail")
    public Result<?> test_xiuzi_colorDetail(@RequestParam(name="id")String id){
        EmbroideredColorTestInfo datainfo = parameterService.select_test_xiuzi_colorDetail(id);
        if(datainfo!=null){
            return Result.ok(datainfo);
        }else{
            return Result.error("未找到对应数据");
        }
    }
    /**
     * 根据id查询绣字字体图片详情
     * @return
     */
    @GetMapping(value = "/test_xiuzi_fontImgDetail")
    public Result<?> test_xiuzi_fontImgDetail(@RequestParam(name="id")String id){
        EmbroideredFontTestInfo datainfo = parameterService.select_test_xiuzi_imgDetail(id);
        if(datainfo!=null){
            return Result.ok(datainfo);
        }else{
            return Result.error("未找到对应数据");
        }
    }


    /**
     * 总后台查询+撞色列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/test_zhuangselist")
    public Result<?> test_zhuangselist(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                         @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                         String category_id,String queryName,String queryTime) {
        Page<ContrastcolorTestInfo> page = new Page<ContrastcolorTestInfo>(pageNo, pageSize);
        IPage<ContrastcolorTestInfo> pageList = parameterService.query_testzhuangsePageList(page,category_id,queryName,queryTime);
        return Result.ok(pageList);
    }

    /**
     * 添加撞色项
     * @param
     * @return boolean
     */
    @PostMapping(value = "/add_zhuangse")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> add_zhuangse(@RequestBody ContrastcolorTestInfo testInfo) {
        System.out.println(testInfo.getCategoryId() + "===");
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getContrastColorName()==null || "".equals(testInfo.getContrastColorName())){
                return Result.error("名称不能为空");
            }
//            Long startTs = System.currentTimeMillis(); // 当前时间戳
//            int random=new Random().nextInt(100)+1;//为变量赋随机值1-99999999;
//            String bianhao_code = "Z-"+startTs.toString();
//            testInfo.setCode(bianhao_code);
            ContrastcolorTestInfo contrastcolorTestInfo = parameterService.query_zhuangseDetailBycode(testInfo.getCode(),testInfo.getTopId());
            if(contrastcolorTestInfo!=null){
                return Result.error("该撞色编号在该品类下面已存在");
            }
            //赋值创建人信息
            testInfo.setCreateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            int code = parameterService.add_zhuangse(testInfo);
            if(code>0){
                return Result.ok("添加成功");
            }else {
                return Result.error("添加失败");
            }
        }catch (Exception e){
            return Result.error("添加失败，参数错误");
        }
    }

    /**
     * 修改撞色
     * @param
     * @return boolean
     */
    @PutMapping(value = "/update_zhuangse")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> update_zhuangse(@RequestBody ContrastcolorTestInfo testInfo) {
        if(testInfo.getId()==null || "".equals(testInfo.getId())){
            return Result.error("参数id不能为空");
        }
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        //定制项dingzhiId
        SmalltemplateTestInfo detail0 = parameterService.select_testDingzhiByname(testInfo.getDingzhiId());
        if(detail0!=null){
            testInfo.setDingzhiId(detail0.getId().toString());
        }
        //品类
        MlccCategoryTestInfo detail1 = parameterService.select_testlbDetailByname(testInfo.getCategoryId());
        if(detail1!=null){
            testInfo.setCategoryId(detail1.getId().toString());
        }
        try {
            //赋值修改人信息
            testInfo.setUpdateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            int code = parameterService.update_zhuangse(testInfo);
            if(code>0){
                return Result.ok("修改成功");
            }else {
                return Result.error("修改失败");
            }
        }catch (Exception e){
            return Result.error("修改失败，参数错误");
        }
    }

    /**
     * 删除撞色
     * @param
     * @return boolean
     */
    @PutMapping(value = "/delete_zhuangse")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> delete_zhuangse(@RequestBody Map<String,Object> params) {
        String canshu_id = params.get("canshu_id").toString();
        System.out.println("===" + canshu_id);
        if(canshu_id==null || "".equals(canshu_id)){
            return Result.error("id不能为空");
        }
        try {
            int code = parameterService.delete_zhuangse(canshu_id);
            if(code>0){
                return Result.ok("删除成功");
            }else {
                return Result.error("删除失败");
            }
        }catch (Exception e){
            return Result.error("删除失败，参数错误");
        }
    }

    /**
     * 根据id查询撞色详情
     * @return
     */
    @GetMapping(value = "/test_zhuangseDetail")
    public Result<?> test_zhuangseDetail(@RequestParam(name="id")String id){
        ContrastcolorTestInfo datainfo = parameterService.query_zhuangseDetail(id);
        if(datainfo!=null){
            return Result.ok(datainfo);
        }else{
            return Result.error("未找到对应数据");
        }
    }

    /**
     * 总后台查询+身体尺寸
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/test_jinti_bodysize")
    public Result<?> test_jinti_bodysize(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                         @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                         String category_id,String type,String queryName,String queryTime) {
        Page<BodySizeTestInfo> page = new Page<BodySizeTestInfo>(pageNo, pageSize);
        IPage<BodySizeTestInfo> pageList = parameterService.query_testBodySizePageList(page,type,category_id,queryName,queryTime);
        return Result.ok(pageList);
    }

    /**
     * 添加尺寸
     * @param
     * @return boolean
     */
    @PostMapping(value = "/add_bodysize")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> add_bodysize(@RequestBody BodySizeTestInfo testInfo) {
        System.out.println(testInfo.getCategoryId() + "===");
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getBodySizename()==null || "".equals(testInfo.getBodySizename())){
                return Result.error("名称不能为空");
            }
            Long startTs = System.currentTimeMillis(); // 当前时间戳
            int random=new Random().nextInt(100)+1;//为变量赋随机值1-99999999;
            String bianhao_code = "CYCC-"+startTs.toString()+random;
            //赋值创建人信息
            testInfo.setCode(bianhao_code);
            testInfo.setCreateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            testInfo.setModuleId("5");
            int code = parameterService.add_testbodySize(testInfo);
            if(code>0){
                return Result.ok("添加成功");
            }else {
                return Result.error("添加失败");
            }
        }catch (Exception e){
            return Result.error("添加失败，参数错误");
        }
    }

    /**
     * 修改尺寸
     * @param
     * @return boolean
     */
    @PutMapping(value = "/update_bodysize")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> update_bodysize(@RequestBody BodySizeTestInfo testInfo) {
        if(testInfo.getId()==null || "".equals(testInfo.getId())){
            return Result.error("参数id不能为空");
        }
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            //赋值修改人信息
            testInfo.setUpdateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            int code = parameterService.update_testbodySize(testInfo);
            if(code>0){
                return Result.ok("修改成功");
            }else {
                return Result.error("修改失败");
            }
        }catch (Exception e){
            return Result.error("修改失败，参数错误");
        }
    }

    /**
     * 删除尺寸
     * @param
     * @return boolean
     */
    @PutMapping(value = "/delete_bodysize")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> delete_bodysize(@RequestBody Map<String,Object> params) {
        String canshu_id = params.get("canshu_id").toString();
        System.out.println("===" + canshu_id);
        if(canshu_id==null || "".equals(canshu_id)){
            return Result.error("id不能为空");
        }
        try {
            int code = parameterService.delete_testbodySize(canshu_id);
            if(code>0){
                return Result.ok("删除成功");
            }else {
                return Result.error("删除失败");
            }
        }catch (Exception e){
            return Result.error("删除失败，参数错误");
        }
    }
    /**
     * 根据id查询尺寸详情
     * @return
     */
    @GetMapping(value = "/test_bodySizeDetail")
    public Result<?> test_bodySizeDetail(@RequestParam(name="id")String id){
        BodySizeTestInfo datainfo = parameterService.query_bodySizeDetail(id);
        if(datainfo!=null){
            return Result.ok(datainfo);
        }else{
            return Result.error("未找到对应数据");
        }
    }


    /**
     * 总后台查询+返修尺寸
     * @param pageNo
     * @param pageSize
     * @returntest_categoryinfoListBytype
     */
    @GetMapping(value = "/test_fanxiu_bodysize")
    public Result<?> test_fanxiu_bodysize(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                         @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                         String category_id,String queryName,String queryTime) {
        Page<CategoryFanxiuTestInfo> page = new Page<CategoryFanxiuTestInfo>(pageNo, pageSize);
        IPage<CategoryFanxiuTestInfo> pageList = parameterService.query_testFanxiuSizePageList(page,category_id,queryName,queryTime);
        if(pageList.getRecords().size()>0){
            for (int i=0;i<pageList.getRecords().size();i++){
                pageList.getRecords().get(i).setFanwei(pageList.getRecords().get(i).getMin()+"至"+pageList.getRecords().get(i).getMax());
            }
        }
        return Result.ok(pageList);
    }
    /**
     * 添加返修尺寸
     * @param
     * @return boolean
     */
    @PostMapping(value = "/add_fanxiubodysize")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> add_fanxiubodysize(@RequestBody CategoryFanxiuTestInfo testInfo) {
        System.out.println(testInfo.getCategoryId() + "===");
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getBodySizename()==null || "".equals(testInfo.getBodySizename())){
                return Result.error("名称不能为空");
            }
            Long startTs = System.currentTimeMillis(); // 当前时间戳
            int random=new Random().nextInt(10000)+1;//为变量赋随机值1-99999999;
            String bianhao_code = "FX-"+startTs.toString()+random;
            //赋值创建人信息
            testInfo.setCreateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            testInfo.setCode(bianhao_code);
            int code = parameterService.add_testFanxiuSize(testInfo);
            if(code>0){
                return Result.ok("添加成功");
            }else {
                return Result.error("添加失败");
            }
        }catch (Exception e){
            return Result.error("添加失败，参数错误");
        }
    }
    /**
     * 修改返修尺寸
     * @param
     * @return boolean
     */
    @PutMapping(value = "/update_fanxiu")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> update_fanxiu(@RequestBody CategoryFanxiuTestInfo testInfo) {
        if(testInfo.getId()==null || "".equals(testInfo.getId())){
            return Result.error("参数id不能为空");
        }
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            //赋值修改人信息
            testInfo.setUpdateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            int code = parameterService.update_testFanxiuSize(testInfo);
            if(code>0){
                return Result.ok("修改成功");
            }else {
                return Result.error("修改失败");
            }
        }catch (Exception e){
            return Result.error("修改失败，参数错误");
        }
    }
    /**
     * 删除返修
     * @param
     * @return boolean
     */
    @PutMapping(value = "/delete_fanxiu")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> delete_fanxiu(@RequestBody Map<String,Object> params) {
        String canshu_id = params.get("canshu_id").toString();
        System.out.println("===" + canshu_id);
        if(canshu_id==null || "".equals(canshu_id)){
            return Result.error("id不能为空");
        }
        try {
            int code = parameterService.delete_testfanxiuSize(canshu_id);
            if(code>0){
                return Result.ok("删除成功");
            }else {
                return Result.error("删除失败");
            }
        }catch (Exception e){
            return Result.error("删除失败，参数错误");
        }
    }
    /**
     * 根据id查询尺寸详情
     * @return
     */
    @GetMapping(value = "/test_fanxiuDetail")
    public Result<?> test_fanxiuDetail(@RequestParam(name="id")String id){
        CategoryFanxiuTestInfo datainfo = parameterService.query_FanxiuSizeDetail(id);
        if(datainfo!=null){
            return Result.ok(datainfo);
        }else{
            return Result.error("未找到对应数据");
        }
    }

    /**
     * 总后台查询+根据类型查询测试类别列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/test_categoryinfoListBytype")
    public Result<?> test_categoryinfoListBytype(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                                 @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                                 String category_id,String type,String queryName,String queryCode) {
        Page<MlccCategoryTestInfo> page = new Page<MlccCategoryTestInfo>(pageNo, pageSize);
        IPage<MlccCategoryTestInfo> pageList = parameterService.query_testCategoryPageListBytype(page,category_id,type,queryName,queryCode);
        return Result.ok(pageList);
    }

    /**
     * 添加品类-工艺
     * @param
     * @return boolean
     */
    @PostMapping(value = "/add_category")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> add_category(@RequestBody MlccCategoryTestInfo testInfo) {
        System.out.println(testInfo.getCategoryName() + "===" + testInfo.getImg());
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getCategoryName()==null || "".equals(testInfo.getCategoryName())){
                return Result.error("工艺类型名称不能为空");
            }
            if(testInfo.getNumbers()==null || "".equals(testInfo.getNumbers())){
                return Result.error("序号不能为空");
            }
            if(testInfo.getImg()==null || "".equals(testInfo.getImg())){
                return Result.error("图片不能为空");
            }
//            MlccCategoryTestInfo categoryTestInfo = parameterService.query_gongyiDetailBycode(testInfo.getCategoryCode(),testInfo.getTopid());
//            if(categoryTestInfo!=null){
//                return Result.error("该工艺类型编号在该品类下面已存在");
//            }
            Long startTs = System.currentTimeMillis(); // 当前时间戳
            int random=new Random().nextInt(1000000)+1;//为变量赋随机值1-99999999;
            String bianhao_code = "GY-"+startTs.toString()+random;
            //赋值品类编号
            testInfo.setCategoryCode(bianhao_code);
            //赋值品类性别
            testInfo.setCategorySex(0);
            //赋值模块id
//            testInfo.setParentId("4");
//            testInfo.setIsType(4);
            //赋值创建人信息
            testInfo.setCreateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            int code = parameterService.add_category_pinglei(testInfo);
            if(code>0){
                //根据编号查询工艺
                MlccCategoryTestInfo categoryTestInfo = parameterService.select_testcategoryDetailBycode(bianhao_code);
                if(categoryTestInfo!=null){
                    //根据编号修改工艺的编号
                    parameterService.update_gongyicode_code("GY-0"+categoryTestInfo.getId(),bianhao_code);
                }
                return Result.ok("添加成功");
            }else {
                return Result.error("添加失败");
            }
        }catch (Exception e){
            return Result.error("添加失败，参数错误");
        }
    }

    /**
     * 修改测试品类-工艺
     * @param
     * @return boolean
     */
    @PutMapping(value = "/update_category")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> update_category(@RequestBody MlccCategoryTestInfo testInfo) {
        System.out.println(testInfo.getCategoryName() + "===" + testInfo.getImg());
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getCategoryName()==null || "".equals(testInfo.getCategoryName())){
                return Result.error("品类名称不能为空");
            }
            if(testInfo.getNumbers()==null || "".equals(testInfo.getNumbers())){
                return Result.error("序号不能为空");
            }
            if(testInfo.getImg()==null || "".equals(testInfo.getImg())){
                return Result.error("图片不能为空");
            }
            testInfo.setUpdateBy(create_by);
            testInfo.setSex("0");
            int code = parameterService.update_category_pingleiName(testInfo);
            if(code>0){
                return Result.ok("编辑成功");
            }else {
                return Result.error("编辑失败");
            }
        }catch (Exception e){
            return Result.error("编辑失败，参数错误");
        }
    }

    /**
     * 删除品类或工艺
     * @param
     * @return boolean
     */
    @PutMapping(value = "/delete_category")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> delete_category(@RequestBody Map<String,Object> params) {
        String canshu_id = params.get("canshu_id").toString();
        System.out.println("===" + canshu_id);
        if(canshu_id==null || "".equals(canshu_id)){
            return Result.error("id不能为空");
        }
        try {
            int code = parameterService.delete_testcategory(canshu_id);
            if(code>0){
                return Result.ok("删除成功");
            }else {
                return Result.error("删除失败");
            }
        }catch (Exception e){
            return Result.error("删除失败，参数错误");
        }
    }

    /**
     * 修改测试类别表的-采用体型数据
     * @param
     * @return boolean
     */
    @PutMapping(value = "/update_category_size")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> update_category_size(@RequestBody Map<String,Object> params) {
        String category_id = params.get("category_id").toString();
        String is_size = params.get("is_size").toString();
        System.out.println("===" + category_id+"==="+is_size);
        try {
            int code = parameterService.update_category_size(category_id,is_size);
            if(code>0){
                return Result.ok("操作成功");
            }else {
                return Result.error("操作失败");
            }
        }catch (Exception e){
            return Result.error("操作失败，参数错误");
        }
    }

    /**
     * 总后台查询+类别的加急服务
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/category_addprice_list")
    public Result<?> category_addprice_list(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                            @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                            String category_id,String partent_id,String queryName,String queryTime) {
        Page<AddSystemPriceInfo> page = new Page<AddSystemPriceInfo>(pageNo, pageSize);
        IPage<AddSystemPriceInfo> pageList = parameterService.query_addpricePageList(page,category_id,partent_id,queryName,queryTime);
        return Result.ok(pageList);
    }
    /**
     * 添加测试加急项
     * @param
     * @return boolean
     */
    @PostMapping(value = "/add_test_addpriceinfo")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> add_test_addpriceinfo(@RequestBody AddSystemPriceInfo testInfo) {
        System.out.println(testInfo.getPremiumItem());
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getPartentId()==null || "".equals(testInfo.getPartentId())){
                return Result.error("请先添加收费类型");
            }
            if(testInfo.getPremiumItem()==null || "".equals(testInfo.getPremiumItem())){
                return Result.error("加急项名称不能为空");
            }
            String codefanxiu = UUID.randomUUID().toString().substring(0,12);
            //8位随机数
            int random=new Random().nextInt(10000)+1;//为变量赋随机值1-99999999;
            String category_code = codefanxiu+random;
            //赋值编号
            testInfo.setPremiumCode(category_code);
            //赋值创建人信息
            testInfo.setCreateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            int code = parameterService.add_addsysytemprice(testInfo);
            if(code>0){
                return Result.ok("添加成功");
            }else {
                return Result.error("添加失败");
            }
        }catch (Exception e){
            return Result.error("添加失败，参数错误");
        }
    }

    /**
     * 修改测试测试加急项
     * @param
     * @return boolean
     */
    @PutMapping(value = "/update_test_addpriceinfo")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> update_test_addpriceinfo(@RequestBody AddSystemPriceInfo testInfo) {
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getPremiumItem()==null || "".equals(testInfo.getPremiumItem())){
                return Result.error("加急项名称不能为空");
            }
            testInfo.setUpdateBy(create_by);
            int code = parameterService.update_addsysytemprice(testInfo);
            if(code>0){
                return Result.ok("编辑成功");
            }else {
                return Result.error("编辑失败");
            }
        }catch (Exception e){
            return Result.error("编辑失败，参数错误");
        }
    }

    /**
     * 删除测试测试加急项
     * @param
     * @return boolean
     */
    @PutMapping(value = "/delete_test_addpriceinfo")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> delete_test_addpriceinfo(@RequestBody Map<String,Object> params) {
        String canshu_id = params.get("canshu_id").toString();
        System.out.println("===" + canshu_id);
        if(canshu_id==null || "".equals(canshu_id)){
            return Result.error("id不能为空");
        }
        try {
            int code = parameterService.delete_addsysytemprice(canshu_id);
            if(code>0){
                return Result.ok("删除成功");
            }else {
                return Result.error("删除失败");
            }
        }catch (Exception e){
            return Result.error("删除失败，参数错误");
        }
    }
    /**
     * 根据id查询收费项
     * @return
     */
    @GetMapping(value = "/query_syspriceByid")
    public Result<?> query_syspriceByid(@RequestParam(name="dinghzi_id")String dinghzi_id){
        AddSystemPriceInfo datainfo = parameterService.query_addsyspriceDetail(dinghzi_id);
        if(datainfo!=null){
            return Result.ok(datainfo);
        }else{
            return Result.error("未找到对应数据");
        }
    }

    /**
     * 查询所有加价项服务-上级
     * @return
     */
    @GetMapping(value = "/query_all_topaddsysprice")
    public Result<?> query_all_topaddsysprice(@RequestParam(name="category_id")String category_id){
        List<AddSystemPriceInfo> datalist= parameterService.query_alladdsysprice(category_id);
        if(datalist.size()>0){
            return Result.ok(datalist);
        }else{
            return Result.error("未找到对应数据");
        }
    }


    /**
     * 添加绣字-高度
     * @param
     * @return boolean
     */
    @PostMapping(value = "/add_xiuzi_height")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> add_xiuzi_height(@RequestBody EmbroidedHeightInfo testInfo) {
        System.out.println(testInfo.getEmbroideredHeight());
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getEmbroideredHeight()==null || "".equals(testInfo.getEmbroideredHeight())){
                return Result.error("绣字高度不能为空");
            }
            EmbroidedHeightInfo datainfo = parameterService.query_xiuziHeightDetailBycode(testInfo.getEmbroideredHeight(),1,testInfo.getCategoryId());
            if(datainfo!=null){
                return Result.error("该品类下绣字高度已存在");
            }
//            EmbroidedHeightInfo datainfo2 = parameterService.query_xiuziHeightDetailBycode(testInfo.getHeightCode(),2,testInfo.getCategoryId());
//            if(datainfo2!=null){
//                return Result.error("该品类下绣字高度编码已存在");
//            }
            Long startTs = System.currentTimeMillis(); // 当前时间戳
            int random=new Random().nextInt(100)+1;//为变量赋随机值1-99999999;
            String bianhao_code = "HEIGHT"+startTs.toString()+random;
            testInfo.setHeightCode(bianhao_code);
            //赋值创建人信息
            testInfo.setCreateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            int code = parameterService.add_xiuzi_height(testInfo);
            if(code>0){
                return Result.ok("添加成功");
            }else {
                return Result.error("添加失败");
            }
        }catch (Exception e){
            return Result.error("添加失败，参数错误");
        }
    }

    /**
     * 修改绣字-gaodu
     * @param
     * @return boolean
     */
    @PutMapping(value = "/update_xiuzi_height")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> update_xiuzi_height(@RequestBody EmbroidedHeightInfo testInfo) {
        if(testInfo.getId()==null || "".equals(testInfo.getId())){
            return Result.error("参数id不能为空");
        }
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getEmbroideredHeight()==null || "".equals(testInfo.getEmbroideredHeight())){
                return Result.error("绣字高度不能为空");
            }
            EmbroidedHeightInfo datainfo = parameterService.query_xiuziHeightDetailBycode(testInfo.getEmbroideredHeight(),1,testInfo.getCategoryId());
            if(datainfo!=null){
                return Result.error("该品类下绣字高度已存在");
            }
//            EmbroidedHeightInfo datainfo2 = parameterService.query_xiuziHeightDetailBycode(testInfo.getHeightCode(),2,testInfo.getCategoryId());
//            if(datainfo2!=null){
//                return Result.error("该品类下绣字高度编码已存在");
//            }
            //赋值修改人信息
            testInfo.setUpdateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            int code = parameterService.update_xiuzi_height(testInfo);
            if(code>0){
                return Result.ok("修改成功");
            }else {
                return Result.error("修改失败");
            }
        }catch (Exception e){
            return Result.error("修改失败，参数错误");
        }
    }

    /**
     * 删除绣字-高度
     * @param
     * @return boolean
     */
    @PutMapping(value = "/delete_xiuzi_height")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> delete_xiuzi_height(@RequestBody Map<String,Object> params) {
        String canshu_id = params.get("canshu_id").toString();
        System.out.println("===" + canshu_id);
        if(canshu_id==null || "".equals(canshu_id)){
            return Result.error("id不能为空");
        }
        try {
            int code = parameterService.delete_xiuzi_height(canshu_id);
            if(code>0){
                return Result.ok("删除成功");
            }else {
                return Result.error("删除失败");
            }
        }catch (Exception e){
            return Result.error("删除失败，参数错误");
        }
    }
    /**
     * 根据id查询绣字高度详情
     * @return
     */
    @GetMapping(value = "/query_xiuziHeightDetail")
    public Result<?> query_xiuziHeightDetail(@RequestParam(name="height_id")String height_id){
        EmbroidedHeightInfo datainfo = parameterService.query_xiuziHeightDetail(height_id);
        if(datainfo!=null){
            return Result.ok(datainfo);
        }else{
            return Result.error("未找到对应数据");
        }
    }

}
